package com.basker.pisces.domain.element.meta;

import java.util.ArrayList;
import java.util.List;

import org.springframework.util.Assert;

import com.basker.pisces.core.meta.IDataObjectMeta;
import com.basker.pisces.core.meta.annotation.CollectionField;
import com.basker.pisces.core.meta.annotation.DataField;
import com.basker.pisces.core.meta.annotation.DataObjectMeta;
import com.basker.pisces.core.meta.bean.BeanMetaManager;
import com.basker.pisces.utils.ClassUtils;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@DataObjectMeta
public class ElementType extends Descriptor {

    @DataField
    private String elementClass;

    @CollectionField
    private List<PropertyDescriptor> propertyDescriptors = new ArrayList<>();

    public IDataObjectMeta getDataObjectMeta() {
        Assert.hasText(this.elementClass, "property 'elementClass' is required");

        Class<?> elementCls = ClassUtils.getClass(this.elementClass);
        return BeanMetaManager.getBeanMeta(elementCls);
    }

}
